package com.hn.kiss.modules.sys.dto;

import com.google.common.base.Converter;
import com.hn.kiss.modules.sys.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDate;

@Data
@ApiModel(value = "RegisterDTO对象", description = "用户注册DTO")
public class RegisterDTO {

    @ApiModelProperty(value = "姓名")
    private String realname;

    @ApiModelProperty(value = "昵称")
    private String nickname;

    @ApiModelProperty(value = "性别")
    private String sex;

    @ApiModelProperty(value = "出生日期")
    private LocalDate dateOfBirth;

    @ApiModelProperty(value = "手机号")
    private String phone;

    @ApiModelProperty(value = "身份证号")
    private String idno;

    @NotBlank
    @Email
    @ApiModelProperty(value = "邮箱", required = true)
    private String emall;

    @NotBlank
    @Size(min = 6, max = 20)
    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "地址省")
    private String addressProvince;

    @ApiModelProperty(value = "地址市")
    private String addressCity;

    @ApiModelProperty(value = "地址县")
    private String addressCounty;

    @ApiModelProperty(value = "地址详细")
    private String addressDetail;

    @ApiModelProperty(value = "机构代码")
    private String orgCode;
    
    public User convertToUser(){
        RegisterDTOConver registerDTOConver = new RegisterDTOConver();
        User user = registerDTOConver.doForward(this);
        return user;
    }
    public RegisterDTO convertFor(User user){
        RegisterDTOConver registerDTOConver = new RegisterDTOConver();
        RegisterDTO registerDTO = registerDTOConver.doBackward(user);
        return registerDTO;
    }
    
    public static class RegisterDTOConver extends Converter<RegisterDTO, User> {
    
        @Override
        protected User doForward(RegisterDTO registerDTO) {
            User user = new User();
            BeanUtils.copyProperties(registerDTO, user);
            return user;
        }
    
        @Override
        protected RegisterDTO doBackward(User user) {
            RegisterDTO registerDTO = new RegisterDTO();
            BeanUtils.copyProperties(user, registerDTO);
            return registerDTO;
    
        }
    }


}
